package com.dis.service.controller.admin;

import com.dis.common.annotation.CheckPermission;
import com.dis.pojo.dto.PolicyDTO;
import com.dis.pojo.queryDTO.PolicyPageQueryDTO;
import com.dis.common.result.PageResult;
import com.dis.common.result.Result;
import com.dis.service.service.PolicyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("admin/policy")
@Api(tags = "报销策略管理接口")
@Slf4j
public class PolicyController {

    @Autowired
    private PolicyService policyService;

    /**
     * 新增报销策略
     * @param policyDTO
     * @return
     */
    @PostMapping
    @ApiOperation("新增报销策略")
    @CheckPermission("policy:add")
    public Result save(@RequestBody PolicyDTO policyDTO) {
        log.info("新增报销策略：{}", policyDTO);
        policyService.save(policyDTO);
        return Result.success();
    }

    /**
     * 分页查询
     * @param policyPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("分页查询报销策略")
    @CheckPermission("policy:query")
    public Result<PageResult> page(PolicyPageQueryDTO policyPageQueryDTO) {
        log.info("分页查询报销策略：{}", policyPageQueryDTO);
        PageResult pageResult = policyService.pageQuery(policyPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 启用或禁用报销策略
     * @param status
     * @param id
     * @return
     */
    @PostMapping("/status/{status}")
    @ApiOperation("启用或禁用报销策略")
    @CheckPermission("policy:edit")
    public Result startOrStop(@PathVariable Integer  status, Long id) {
        log.info("启用或禁用报销策略：{}, {}", status, id);
        policyService.startOrStop(status, id);
        return Result.success();
    }

    /**
     * 根据id删除报销策略
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation("删除报销策略")
    @CheckPermission("policy:delete")
    public Result deleteById(@PathVariable Long id) {
        log.info("删除报销策略：{}", id);
        policyService.deleteById(id);
        return Result.success();
    }

    /**
     * 编辑报销策略
     * @param policyDTO
     * @return
     */
    @PutMapping
    @ApiOperation("编辑报销策略")
    @CheckPermission("policy:edit")
    public Result update(@RequestBody PolicyDTO policyDTO) {
        log.info("编辑报销策略：{}", policyDTO);
        policyService.update(policyDTO);
        return Result.success();
    }
}
